//
//  SuperviseTaskIssueCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/1/9.
//

import Foundation
import UIKit

class SuperviseTaskIssueCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withItem item: SpRwbgtzModal?) {
        titleL.text = item?.rwmc
        chargeL.text = item?.tjsj
//        countL.text = item?.zgzt
    }
    
    func setupUI() {
        addSubview(iconIV)
        iconIV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(14)
            make.width.height.equalTo(25)
        }
        
        addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.left.equalTo(iconIV.snp.right).offset(15)
            make.right.equalToSuperview().offset(-30)
            make.top.equalToSuperview().offset(14)
        }
        
        addSubview(chargeL)
        chargeL.snp.makeConstraints { make in
            make.top.equalTo(titleL.snp.bottom).offset(8)
            make.left.equalTo(titleL.snp.left)
            make.bottom.equalToSuperview().offset(-14)
            make.height.equalTo(20)
        }
        
        addSubview(indicatorIV)
        indicatorIV.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
            make.width.equalTo(10)
        }
        
        addSubview(countL)
        countL.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(indicatorIV.snp.left).offset(-10)
        }
        
        let line = UIView()
        line.backgroundColor = .hex("#EFEFEF")
        addSubview(line)
        line.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(0.5)
        }
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        if highlighted {
            backgroundColor = .bg
        } else {
            backgroundColor = .white
        }
    }
    
    lazy var iconIV: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "ic_spreport_4"))
        imageView.contentMode = UIView.ContentMode.scaleAspectFit
        return imageView
    }()
    
    lazy var titleL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 16)
        label.textColor = .hex("#333333")
        label.numberOfLines = 0
        return label
    }()
    
    lazy var chargeL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .hex("#9A9A9A")
        return label
    }()
    
    lazy var countL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 15)
        label.textColor = .hex("#0C8786")
        return label
    }()
    
    lazy var indicatorIV: UIImageView = {
        let imageView = UIImageView(image: UIImage(systemName: "chevron.right"))
        imageView.tintColor = .hex("#A5A5A5")
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
}
